<template>
    <view class="STH_shop_coupon">
        <!-- component/coupon/coupon.wxml -->
        <view class="store-card">
            <block v-for="(item, idx) in CouponList" :key="idx">
                <view class="store-card-list">
                    <view @tap="doget" :data-info="item" class="store-card-list-box">
                        <view class="store-card-list-left">
                            <view class="bor-right">
                                <i></i>
                                <i></i>
                                <i></i>
                                <i></i>
                                <i></i>
                                <i></i>
                                <i></i>
                                <i></i>
                                <i></i>
                                <i></i>
                            </view>
                            <text class="span">
                                ￥
                                <text class="em">{{ item.Ffacevalue }}</text>
                            </text>
                            <text class="p">{{ item.Fdesc }}</text>
                        </view>
                        <view class="store-card-list-right">
                            {{ item.Fctype == 1 ? '立即获取' : '马上购买' }}
                            <i></i>
                        </view>
                    </view>
                </view>
            </block>
        </view>
    </view>
</template>

<script>
// component/coupon/coupon.js
var util = require('../../utils/util.js');
var api = require('../../utils/prom.js');
export default {
    data() {
        return {
            prop: null,
            CouponList: []
        };
    },
    /**
     * 组件的属性列表
     */
    props: {
        con: {
            type: Object,
            default: null
        }
    },
    mounted() {
        // 处理小程序 ready 生命周期
        this.$nextTick(() => this.ready());
    },
    /**
     * 组件的方法列表
     */
    methods: {
        ready: function () {
            var that = this;
            var prop = JSON.parse(that.con.prop);
            console.log(prop);
			that.prop = prop; 
            var CouponList = [];
            for (var g = 0; g < that.con.CouponList.length; g++) {
                var row = that.con.CouponList[g];
                var index = row['Fsdate'].indexOf('T');
                if (index > 0) {
                    row['Fsdate'] = row['Fsdate'].substr(0, index);
                }
                var index = row['Fedate'].indexOf('T');
                if (index > 0) {
                    row['Fedate'] = row['Fedate'].substr(0, index);
                }
                if (row.Fsdtype == 1) {
                    var Fsdt = row['Fsdate'];
                } else {
                    var Fsdt = '领取时间';
                }
                if (row.Fsdtype == 1) {
                    var Fedt = row['Fedate'];
                } else {
                    var Fedt = '领取后' + row.Fday + '天';
                }
                var Fdesc = '';
                var Feditdesc = '；';
                if (row.Fctype == 1) {
                    if (row.Ffullvalue == 0) {
                        if (!row.Fpids) {
                            Feditdesc = '全场无门槛';
                            Fdesc = '全场无门槛';
                        } else {
                            Fdesc = '指定商品无门槛';
                            Feditdesc = '指定商品无门槛消费';
                        }
                    } else {
                        Fdesc = '满￥' + row.Ffullvalue + '使用';
                        if (!row.Fpids) {
                            Feditdesc = '全场满￥' + row.Ffullvalue + '使用';
                        } else {
                            Feditdesc = '指定商品满￥' + row.Ffullvalue;
                        }
                    }
                } else {
                    Fdesc = '仅需￥' + row.Ffullvalue + '使用';
                }
                var newobj = {
                    Feditdesc: Fdesc,
                    Ffacevalue: parseInt(row.Ffacevalue),
                    Fdesc: Fdesc,
                    Fctype: row.Fctype,
                    Fsdate: Fsdt,
                    Fedate: Fedt,
                    Ftype: 7,
                    Ftypeid: row.Fid
                };
                console.log(newobj);
                CouponList.push(newobj);
            }
            that.CouponList =CouponList;
        },

        //获取优惠券
        doget: function (e) {
            var that = this;
            var row = e.currentTarget.dataset.info;
            //未登陆 先登录
            var userinfo = uni.getStorageSync('user');
            if (util.isEmpty(userinfo.Fspuid)) {
                var url = '/pages/userLogin/userLogin';
                uni.navigateTo({
                    url: url
                });
            }
            //优惠券
            if (row.Fctype == 1) {
                var param = {
                    token: uni.getStorageSync('token')
                };
                api.request('SpActivity', 'get', param, function (res) {
                    var md5 = res.data.Message;
                    var url = 'SpCoupon?token=' + uni.getStorageSync('token');
                    var data = {
                        Fid: row.Ftypeid,
                        Fsign: md5
                    };
                    api.request(url, 'post', data, function (res) {
                        uni.showModal({
                            title: '',
                            content: '恭喜您，成功获取一张优惠劵！',
                            showCancel: false
                        });
                    });
                });
            }
            //抵用劵
            else if (row.Fctype == 2) {
                var url = '/pages/coupon/coupon?Fid=' + row.Fid;
                uni.navigateTo({
                    url: url
                });
            }
        }
    },
    created: function () {}
};
</script>
<style>
@import './coupon.css';
</style>
